#include "e2d/ui/LoggerLayer.h"
#include "e2d/ui/State.h"

e2d::LoggerLayer::LoggerLayer()
	:fxcc::imgui::Layer("Logger")
{

	ztclog::pushFunction([=](const ztclog::Line& l) {

		this->m_Lines.push_back(l);
		this->m_RefreshFlag = true;
		});
	
}

void e2d::LoggerLayer::HandleFunc()
{



}

void e2d::LoggerLayer::ViewFunc()
{
	for (const auto& line : m_Lines)
	{
		if (line.m_Type != ztclog::Line::_line_debug_)
			ImGui::Text("%s %s", "[ info ]", line.m_Text.c_str());
	}
	for (int i = 0; i < m_BottomBlankLines; i++)
	{
		ImGui::Text("");
	}

	if (m_RefreshFlag)
	{
		ImGui::SetScrollHereY(1.0f);
		m_RefreshFlag = false;
	}

	if (ImGui::BeginPopupContextWindow())
	{

		if (ImGui::MenuItem("clear"))
		{

			Clear();
		}

		ImGui::EndPopup();
	}
}

void e2d::LoggerLayer::Clear()
{
	m_Lines.clear();
}

